﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Administrator_AdminControl_BusinessPackage : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadPackageVIP();
        }
    }

    

    private void loadPackageVIP()
    {
        try
        {
            using (Up1VNDataContext db = new Up1VNDataContext())
            {
                var query = (from o in db.PointBackages select o);
                var queryList = query.ToList();
                if (queryList.Count > 0)
                {
                    PagedDataSource page = new PagedDataSource();
                    page.DataSource = queryList;
                    rptPackageVIP.DataSource = page;
                    rptPackageVIP.DataBind();

                  
                }
               
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
            try
            {
                using (Up1VNDataContext db = new Up1VNDataContext())
                {
                    PointBackage P = new PointBackage();
                    P.PointBackage_Name = txtName.Value;
                    P.PointBackage_Point = Int32.Parse(txtPoint.Value);
                    P.PointBackage_DayNo = Int32.Parse(txtTime.Text);
                    db.PointBackages.InsertOnSubmit(P);
                    db.SubmitChanges();
                    loadPackageVIP();
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        
    }
    
    protected void rptPackageVIP_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            if(e.CommandName=="delete")
            {
                using (Up1VNDataContext db = new Up1VNDataContext())
                {
                    var query = from o in db.PointBackages where o.PointBackage_Id == Int32.Parse(e.CommandArgument.ToString()) select o;
                    db.PointBackages.DeleteAllOnSubmit(query);
                    db.SubmitChanges();
                    loadPackageVIP();
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}